package O2_Selection_Sort;

/**
 * Created by Choisaaaa on 2018/6/4.
 */
public class Student implements Comparable<Student> {
    private String name;
    private int score;

    public Student(String name,int sorce){
        this.score = sorce;
        this.name = name;
    }

    // 定义Student的compareTo函数
    // 如果分数相等，则按照名字的字母序排序
    // 如果分数不等，则分数高的靠前
    public int compareTo(Student student) {

        if(student.score == this.score){
            return  this.name.compareTo(student.name);
        }
        if(this.score < student.score){
            return 1;
        }else if (this.score > student.score){
            return  -1;
        }else
            return 0;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sorce=" + score +
                '}';
    }
}
